<template>
    <div class="proxy">
        <div class="proxy-wrapper">
            <div class="head-img">
                <img :src="logo" width="66" height="66" alt="">
            </div>
            <div class="prox-content">
                <div class="prox-select">
                    <input type="radio" id="area" checked name="select" v-model="val" value="0">
                    <label for="area"></label>
                    <span>我要成为区代理</span>
                </div>
                <div class="prox-select">
                    <input type="radio" id="city" name="select" v-model="val" value="1">
                    <label for="city"></label>
                    <span>我要成为市代理</span>
                </div>
            </div>
            <button class="prox-btn" @click="_sendData">确定</button>
            <div class="close" @click="_close">
                <img :src="close" width="20" height="20" alt="">
            </div>
        </div>
    </div>
</template>

<script>
import close from '@imgs/self/close.png'
import logo from '@imgs/login/login_logo.png'
import { tokenPost, jtpost, gtpost, tokenLink, jtget } from '@api/axiosByToken'

export default {
    name: 'Proxy',
    data() {
        return {
            logo: logo,
            close,
            val: '',
        }
    },
    methods: {
        _close() {
            this.$emit('close')
        },
        // 点击判断
        _sendData() {
            if (this.val === '') {
                this.$Message.warning('请选择市代理或者区代理')
                return
            }
            if (window.localStorage.proxyState === '1') {
                this.$Message.warning('你已经申请过不能重复申请')
                 this.$emit('close')
                return
            }
            this._sendProxy()
        },
        // 发送数据
        _sendProxy() {
            let prox = {
                id: window.localStorage.ygMemberIdentityId,
                isCityOrArea: this.val
            }
            jtpost(tokenLink.prxy, prox).then(re => {
                if (re.status === 0) {
                    this.$emit('close')
                    window.localStorage.proxyState = '1'
                    this.$Message.success('发送成功')
                } else {
                    this.$Message.warning(re.msg)
                }
            })
        }
    }
}
</script>